import os,sys
import pandas as pd

class data_prase():
    def __init__(self, datapath):
        self.datapath = datapath

    def read_data_from_csv(filepath):
        if not os.path.exists(filepath):
            print("cannot get file " + filepath)
            sys.exit()
        orgdata = pd.read_csv(filepath, encoding='gbk')
        print(orgdata)
        
        data = []
        name = list(orgdata['name'])
        text = []
        for x in orgdata['text']:
            if pd.isna(x):
                text.append((False, x))
            else:
                text.append((True, x.split('_*_')))
                
        img = []
        for x in orgdata['img']:
            if pd.isna(x):
                img.append((False, x))
            else:
                img.append((True, x.split(',')))

        repeat = [int(x) for x in orgdata['repeat']]
               
        atone = []
        for x in orgdata['someone']:
            if pd.isna(x):
                atone.append((False, x))
            else:
                rawdata = []
                for one in x.split('@'):
                    rawdata.append(one[:-1])
                del rawdata[0]
                atone.append((True, rawdata))
        print(atone)

        namenum = len(name)
        for i in range(0, namenum):
            data.append((name[i], text[i], img[i], repeat[i], atone[i]))
        return data
        # for one in 


